<template>
    <!-- 列表页面 -->
    <div class="tableSample">
        <div class="header">
            <div class="header-left">
                <p class="title">提现列表
                </p>
            </div>
            <div class="header-right">
                <lin-search @query="onQueryChangeTwo" placeholder="请输入省份" />
                <lin-search @query="onQueryChangeThree" placeholder="请输入城市" style="margin-left: 20px;" />
                <lin-search @query="onQueryChangeFour" placeholder="请输入区/县" style="margin-left: 20px;" />
                <el-select  size="medium" filterable v-model="search.type" @change="handleChangeType" placeholder="请选择类型" clearable style="margin-left: 20px;" >
                    <el-option
                            v-for="(type, index) in adminType"
                            :key="index"
                            :label="type.name"
                            :value="type.id">
                    </el-option>
                </el-select>
            </div>
        </div>
        <!-- 表格 -->
        <el-table
                :data="tableData"
                stripe
                border
                v-loading="loading"
        >
            <el-table-column
                    :show-overflow-tooltip="true"
                    prop="name"
                    label="提现人姓名">
            </el-table-column>
            <el-table-column
                    :show-overflow-tooltip="true"
                    prop="bank_name"
                    label="银行名称">
            </el-table-column>
            <el-table-column
                    :show-overflow-tooltip="true"
                    prop="bank_no"
                    label="银行账号">
            </el-table-column>
            <el-table-column
                    :show-overflow-tooltip="true"
                    prop="money"
                    label="提现金额">
            </el-table-column>
            <el-table-column
                    :show-overflow-tooltip="true"
                    prop="type_name"
                    label="类型">
            </el-table-column>
            <el-table-column
                    :show-overflow-tooltip="true"
                    prop="province"
                    label="省份">
            </el-table-column>
            <el-table-column
                    :show-overflow-tooltip="true"
                    prop="city"
                    label="城市">
            </el-table-column>
            <el-table-column
                    :show-overflow-tooltip="true"
                    prop="county"
                    label="区/县">
            </el-table-column>
            <el-table-column
                    :show-overflow-tooltip="true"
                    prop="status_name"
                    label="状态">
            </el-table-column>
            <el-table-column
                    :show-overflow-tooltip="true"
                    prop="create_time"
                    label="申请时间">
            </el-table-column>
            <!-- 操作列 -->
            <el-table-column label="操作" fixed="right" width="180" >
                <template slot-scope="scope">
                    <el-button
                            type="primary"
                            plain
                            size="mini"
                            @click.native.prevent.stop="handleEdit(scope)"
                            v-if="scope.row.status === 1"
                    >审核通过
                    </el-button>
                </template>
            </el-table-column>
        </el-table>
        <!-- 分页 -->
        <div class="pagination">
            <el-pagination
                    @current-change="handleCurrentChange"
                    :background="true"
                    :page-size="pageCount"
                    :current-page="currentPage"
                    v-if="refreshPagination"
                    layout="total,prev, pager, next, jumper"
                    :total="total_nums"
            ></el-pagination>
        </div>
    </div>
</template>

<script>
import member from '@/models/member'
import LinSearch from '@/components/base/search/lin-search'

export default {
  components: {
    LinSearch,
  },
  data() {
    return {
      adminType: [
        { id: 1, name: '会员' },
        { id: 2, name: '省级合伙人' },
        { id: 3, name: '市级合伙人' },
        { id: 4, name: '区/县合伙人' },
        { id: 5, name: '助理' },
      ],
      tableColumn: [
        { prop: 'name', label: '姓名' },
        { prop: 'bank_name', label: '所属银行' },
        { prop: 'bank_no', label: '银行账号' },
        { prop: 'money', label: '提现金额' },
        { prop: 'status_name', label: '状态' },
        { prop: 'create_time', label: '申请时间' },
      ],
      tableData: [],
      operate: [],
      loading: false,
      search: {
        type: '',
      },
      province: '',
      city: '',
      county: '',
      costId: 0,
      // 分页相关
      refreshPagination: true, // 页数增加的时候，因为缓存的缘故，需要刷新Pagination组件
      currentPage: 1, // 默认获取第一页的数据
      pageCount: 10, // 每页10条数据
      total_nums: 0, // 分组内的总数
    }
  },
  computed: {},
  created() {
    this.loading = true
    // 获取数据
    this._getTableData(this.currentPage, this.pageCount)
    // 操作栏
    this.operate = [
      { name: '审核通过', func: 'handleEdit', type: 'primary' },
    ]
  },
  methods: {
    // 获取数据
    async _getTableData(start, count) {
      const res = await member.getWithdrawalList(start, count, {
        type: this.search.type, province: this.province, city: this.city, county: this.county,
      })
      this.tableData = res.data
      this.total_nums = res.count
      this.$nextTick(() => {
        this.loading = false
      })
    },
    // 切换分页
    async handleCurrentChange(val) {
      this.currentPage = val
      this.loading = true
      this._getTableData(this.currentPage, this.pageCount)
    },
    handleEdit(val) {
      this
        .$confirm('此操作将审核通过, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning',
        })
        .then(async () => {
          this.loading = true
          const res = await member.updateWithdrawal({ id: val.row.id })
          if (res.error_code === 0) {
            this.$message.success(`${res.msg}`)
          }
          this._getTableData(this.currentPage, this.pageCount)
        })
    },
    // 搜索姓名
    handleChangeType() {
      this.loading = true
      this.currentPage = 1
      this._getTableData(
        this.currentPage,
        this.pageCount,
      )
    },
    // 搜索省份
    onQueryChangeTwo(query) {
      this.province = query.trim()
      if (!query) {
        this._getTableData(1, 10)
        return
      }
      this.loading = true
      this.currentPage = 1
      this._getTableData(
        this.currentPage,
        this.pageCount,
      )
    },
    // 搜索城市
    onQueryChangeThree(query) {
      this.city = query.trim()
      if (!query) {
        this._getTableData(1, 10)
        return
      }
      this.loading = true
      this.currentPage = 1
      this._getTableData(
        this.currentPage,
        this.pageCount,
      )
    },
    // 搜索区/县
    onQueryChangeFour(query) {
      this.county = query.trim()
      if (!query) {
        this._getTableData(1, 10)
        return
      }
      this.loading = true
      this.currentPage = 1
      this._getTableData(
        this.currentPage,
        this.pageCount,
      )
    },
  },
}
</script>

<style lang="scss" scoped>
    .tableSample {
        padding: 0 0 30px;

        .header {
            display: flex;
            justify-content: space-between;
            align-items: center;
            padding: 0 30px;
            border-bottom: 1px solid #dae1ed;

            .header-left {
                float: left;

                .title {
                    height: 59px;
                    line-height: 59px;
                    color: $parent-title-color;
                    font-size: 16px;
                    font-weight: 500;
                }
            }

            .header-right {
                float: right;
                display: flex;
                justify-content: space-between;
                align-items: center;
            }
        }

        .table-main {
            padding: 0 30px;
            margin-top: 30px;
        }

        .top-operate {
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin-bottom: 15px;
            margin-top: 30px;
        }

        .sort-input {
            width: 50px;
            background: none;
            justify-content: space-around;
        }

        .table-edit {
            display: flex;
            align-items: center;
            justify-content: space-between;
            width: 100%;
            .content {
                overflow: hidden;
                text-overflow: ellipsis;
                white-space: nowrap;
            }

            .cell-icon {
                cursor: pointer;
                color: #3963bc;
                font-size: 16px;
            }

            .cell-icon-edit {
                display: flex;
                margin-left: 20px;
                width: 50px;
                justify-content: space-between;

                .cell-cancel {
                    cursor: pointer;
                    color: #3963bc;
                    font-size: 16px;
                }

                .cell-save {
                    cursor: pointer;
                    color: #3963bc;
                    font-size: 16px;
                    margin-right: -20px;
                }
            }
        }

        .m-20 {
            margin-bottom: 10px;
            margin-top: 5px;
        }

        .summary {
            display: flex;
            justify-content: flex-start;
            flex-direction: row;

            img {
                width: 135px;
                height: 200px;
            }

            .demo-table-expand {
                font-size: 0;
                margin-left: 30px;
                display: flex;
                flex-direction: column;

                label {
                    width: 90px;
                    color: #99a9bf;
                }

                .el-form-item {
                    margin-right: 0;
                    margin-bottom: 0;
                    display: flex;
                    flex-direction: row;
                }
            }
        }

        .pagination {
            display: flex;
            justify-content: flex-end;
            margin: 20px;
        }
    }
    // dialog
    .tableSample /deep/ .el-dialog__footer {
        text-align: left;
        padding-left: 30px;
    }

    .tableSample /deep/ .el-dialog__header {
        padding-left: 30px;
    }

    .tableSample /deep/ .el-dialog__body {
        padding: 30px;
    }
</style>
